<template>
  <div class="mod-config">
    <basic-container>
      <navigationZDRW :sign="{ a: false, b: true, c: false }"></navigationZDRW>
      <div v-if="showZhong == 1" class="boxsty zhiBiao">
        <div :height="searchheight">
          <span
            style="float: right; margin-top: -30px; cursor: pointer"
            @click="searchchangeadvanced"
            >{{ searchadvanced ? "查询条件收起" : "查询条件展开" }}
            <i
              :class="
                searchadvanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'
              "
            />
          </span>
          <div v-show="searchadvanced">
            <el-form
              :inline="true"
              :model="dataForm"
              @keyup.enter.native="getDataList()"
              class="form-inline"
            >
              <el-form-item label="发起名称">
                <el-input
                  v-model="dataForm.faqiName"
                  placeholder="发起名称"
                  :clearable="true"
                  style="width: 150px"
                ></el-input>
              </el-form-item>
              <el-form-item label="被考核人姓名">
                <el-input
                  v-model="dataForm.ryName"
                  placeholder="被考核人姓名"
                  :clearable="true"
                  style="width: 150px"
                ></el-input>
              </el-form-item>
              <el-form-item label="考核人岗位">
                <el-input
                  v-model="dataForm.userZw"
                  placeholder="考核人岗位"
                  :clearable="true"
                  style="width: 150px"
                ></el-input>
              </el-form-item>
              <el-form-item>
                <el-button
                  icon="el-icon-search"
                  type="primary"
                  class="marginLeft"
                  @click="getDataList()"
                  >检索
                </el-button>
              </el-form-item>
            </el-form>
          </div>
        </div>
        <div class="border-top-theme">
          <div class="mt10" style="overflow: hidden">
            <div style="float: right">
              <el-button
                plain
                type="primary"
                @click="huizong()"
                v-loading.fullscreen.lock="fullscreenLoading"
                >生成考核得分</el-button
              >
              <el-button
                plain
                type="primary"
                @click="endBtn()"
                v-loading.fullscreen.lock="fullscreenLoading"
                >结束</el-button
              >
              <el-button
                plain
                type="primary"
                @click="subAll()"
                v-loading.fullscreen.lock="fullscreenLoading"
                >提交</el-button
              >
            </div>
          </div>
        </div>
        <el-table
          style="width: 100%; margin-top: 10px"
          :data="dataList"
          border
          ref="tableRef"
          v-loading="dataListLoading"
        >
          <el-table-column
            :selectable="checkboxSelect"
            type="selection"
            width="55"
            header-align="center"
            align="center"
          ></el-table-column>
          <el-table-column
            type="index"
            width="80"
            header-align="center"
            align="center"
            label="序号"
          ></el-table-column>
          <el-table-column
            prop="faqiName"
            header-align="center"
            align="center"
            width="200"
            show-overflow-tooltip
            label="发起名称"
          >
          </el-table-column>
          <el-table-column
            prop="ryName"
            header-align="center"
            align="center"
            min-width="120"
            label="被考核人姓名"
          >
          </el-table-column>
          <el-table-column
            prop="userZw"
            header-align="center"
            align="center"
            min-width="120"
            label="被考核人岗位"
          >
          </el-table-column>
          <el-table-column
            prop="stateExplain"
            header-align="center"
            align="center"
            min-width="110"
            label="任务状态"
          >
          </el-table-column>
          <el-table-column
            prop="zp"
            header-align="center"
            align="center"
            min-width="120"
            label="自评分"
          >
          </el-table-column>
          <el-table-column
            prop="pj"
            header-align="center"
            align="center"
            min-width="120"
            label="领导评分"
          >
          </el-table-column>
          <el-table-column
            prop="order"
            header-align="center"
            align="center"
            min-width="120"
            label="其他奖惩"
          >
          </el-table-column>
          <el-table-column
            prop="count"
            header-align="center"
            min-width="110"
            align="center"
            label="最终评分"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.count!='-'">{{ scope.row.count.toFixed(2) }}</span>
              <span v-else>-</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="xiu"
            header-align="center"
            align="center"
            min-width="110"
            label="修正系数"
          >
          </el-table-column>
          <el-table-column
            prop="nan"
            header-align="center"
            align="center"
            min-width="110"
            label="难度系数"
          >
          </el-table-column>
          <el-table-column
            prop="score"
            header-align="center"
            align="center"
            min-width="110"
            label="考核得分"
          >
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            width="350"
            fixed="right"
            label="操作"
          >
            <template slot-scope="scope">
              <el-button
                type="primary"
                plain
                size="small"
                @click="opinionCkeek(scope.row)"
                >查看审批意见</el-button
              >
              <el-button
                type="primary"
                plain
                size="small"
                @click="preview(scope.row)"
                >查看自评</el-button
              >
              <el-button
                type="primary"
                plain
                size="small"
                @click="evaluation(scope.row, 1)"
                >查看评价</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <div class="avue-crud__pagination">
          <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :current-page="pageIndex"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pageSize"
            :total="totalPage"
            background
            layout="total, sizes, prev, pager, next, jumper"
          >
          </el-pagination>
        </div>
      </div>
      <UserCommonSelect
        ref="usercomment"
        @submitfy="submitfy"
      ></UserCommonSelect>
      <zdfqForm
        v-if="showZhong == 2"
        ref="zdfqRef"
        :zdfqForm="zdfqForm"
        v-on:zdrwfqC="zdrwfqC"
      ></zdfqForm>
      <!--          任务自评-->
      <zdzpForm
        v-if="showZhong == 3"
        ref="renwuziping"
        :titleForm="titleForm"
        @fnBackLastPage="fnBackLastPage"
      ></zdzpForm>
      <el-dialog title="领导审批意见" :visible.sync="dialogVisible" width="50%">
        <el-table :data="optionsList" style="width: 100%">
          <el-table-column
            prop="time_"
            label="日期"
            header-align="center"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="ry_name"
            label="审批人"
            header-align="center"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="message_"
            label="审批意见"
            header-align="left"
            align="left"
          >
          </el-table-column>
        </el-table>
      </el-dialog>
    </basic-container>
  </div>
</template>

<script>
import zdfqForm from "@/views/hetongrenwu/components/zhongdianfq-form.vue";
import zdzpForm from "@/views/hetongrenwu/components/zhongdianzp-form.vue";
import { radioTwoList } from "@/api/hetongrenwu/hetonghtxxdjb";
import { validatenull } from "@/util/validate";
import {
  fetchListHz,
  getScore,
  getScorePj,
  score,
  subAll,
  theend,
  getLdshOpinions,
  endAll,
} from "@/api/hetongrenwu/zhongdian/renwutianbao";
import { getObj, isExistRw } from "@/api/hetongrenwu/zhongdian/renwuchuangjian";
import UserCommonSelect from "@/views/hetongrenwu/components/usercomment-select";
export default {
  components: {
    zdfqForm,
    zdzpForm,
    UserCommonSelect,
  },
  data() {
    return {
      titleForm: {},
      optionsStatus: [
        {
          value: 0,
          label: "未发起",
        },
        {
          value: 1,
          label: "已发起",
        },
        {
          value: 2,
          label: "已自评",
        },
        {
          value: 3,
          label: "已评价",
        },
        {
          value: 4,
          label: "已汇总",
        },
      ],
      fullscreenLoading: false,
      dataForm: {},
      radio: "1",
      radioTwo: "1",
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      showZhong: 1,
      zdfqForm: {},
      searchadvanced: true,
      searchheight: "0",
      radioTwoList: radioTwoList,
      jsonData: "",
      shouyuerendataList: [],
      dialogVisible: false,
      optionsList: [],
    };
  },
  created() {
    let params = this.$route.query;
    if (!validatenull(params)) {
      this.radioTwo = params.radioTwo;
    }
    this.getDataList();
  },
  methods: {
    subAll() {
      const rows = this.$refs.tableRef.selection;
      if (rows.length == 0) {
        this.$message({
          type: "error",
          message: "请选择一条任务提交!",
        });
      } else {
        for (var i = 0; i < rows.length; i++) {
          if (rows[i].state == "15" && rows[i].state == "17") {
            this.$message.closeAll();
            this.$message.error(
              "存在不是“领导审核完成”和“结果汇总完成”的数据无法提交"
            );
            return false;
          }
        }
        this.jsonData = JSON.stringify(this.shouyuerendataList);
        this.$nextTick(() => {
          this.$refs.usercomment.init("12", "allTree", this.jsonData, "htcj");
        });
      }
    },
    endBtn() {
      const rows = this.$refs.tableRef.selection;
      if (rows.length == 0) {
        this.$message({
          type: "error",
          message: "请选择一条任务提交!",
        });
      } else {
        for (var i = 0; i < rows.length; i++) {
          if (rows[i].state != "15" && rows[i].state != "17") {
            this.$message.closeAll();
            this.$message.error(
              "存在不是“领导审核完成”和“结果汇总完成”的数据无法结束"
            );
            return false;
          }
        }
        endAll(rows).then(res=>{
          this.$message.success("结束成功");
          this.getDataList();
        })
      }
    },
    submitfy(data) {
      var params = {
        users: data.tableDataUser,
        rows: this.$refs.tableRef.selection,
      };
      this.fullscreenLoading = true;
      subAll(params).then((res) => {
        this.$message.success(res.data.data);
        this.fullscreenLoading = false;
        this.getDataList();
      });
    },
    searchchangeadvanced() {
      this.searchadvanced = !this.searchadvanced;
      if (this.searchadvanced) {
        this.searchheight = "auto";
      }
    },
    opinionCkeek(row) {
      getLdshOpinions({ recordId: row.recordId }).then((res) => {
        console.log(res.data.data);
        this.optionsList = res.data.data;
        this.dialogVisible = true;
      });
    },
    //查看评价
    evaluation(row, type) {
      getScorePj({ id: row.id, showAll: 1 }).then((res) => {
        this.showZhong = 2;
        this.$nextTick(() => {
          var enter = type == 1 ? "3" : "4";
          this.zdfqForm = {
            enter: enter,
            disabled: true,
          };
          this.$refs.zdfqRef.init(res.data.data, "rwck");
        });
      });
    },
    //子集
    zdrwfqC(zdrwfqC) {
      if (zdrwfqC) {
        this.showZhong = 1;
        this.getDataList();
      }
    },
    getDataList() {
      this.dataListLoading = true;
      fetchListHz(
        Object.assign(
          {
            current: this.pageIndex,
            size: this.pageSize,
          },
          this.dataForm
        )
      ).then((response) => {
        this.dataList = response.data.data.records;
        this.totalPage = response.data.data.total;
        this.dataListLoading = false;
      });
    },
    //查看自评
    preview(row) {
      getObj(row.id).then((res) => {
        row.start = res.data.data.rwYxqq;
        row.end = res.data.data.rwYxqz;
        getScore({ id: row.id }).then((res) => {
          this.titleForm = row;
          this.showZhong = 3;
          this.$nextTick(() => {
            var data = {
              dataForm: {
                dataList: res.data.data,
              },
              showTextarea: "hzziping",
            };
            this.$refs.renwuziping.init(data);
          });
        });
      });
    },
    //任务考核返回数据
    fnBackLastPage(data) {
      if (data == "返回原页面") {
        this.showZhong = 1;
      }
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    huizong() {
      const rows = this.$refs.tableRef.selection;
      if (rows.length == 0) {
        this.$message({
          type: "error",
          message: "请选择一条任务汇总!",
        });
      } else {
        this.$confirm("是否要对" + rows[0].faqiName + "进行汇总?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.fullscreenLoading = true;
            score(rows)
              .then((res) => {
                this.$message({
                  type: "success",
                  message: "汇总成功!",
                });
                this.fullscreenLoading = false;
                this.getDataList();
              })
              .catch(() => {
                this.$message({
                  type: "error",
                  message: "汇总失败!",
                });
                this.fullscreenLoading = false;
              });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消",
            });
          });
      }
    },
    checkboxSelect(row, rowIndex) {
      if (
        row.state == "15" ||
        row.state == "16" ||
        row.state == "17" ||
        row.state == "18"
      ) {
        return true;
      } else {
        return false;
      }
    },
  },
};
</script>

<style>
</style>
